package top.frsf.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.frsf.common.annotation.Log;
import top.frsf.common.core.controller.BaseController;
import top.frsf.common.core.domain.AjaxResult;
import top.frsf.common.enums.BusinessType;
import top.frsf.system.domain.TbEquipmentMaintenance;
import top.frsf.system.service.ITbEquipmentMaintenanceService;
import top.frsf.common.utils.poi.ExcelUtil;
import top.frsf.common.core.page.TableDataInfo;

/**
 * 设备类型Controller
 *
 * @author ruoyi
 * @date 2025-09-12
 */
@RestController
@RequestMapping("/system/maintenance")
public class TbEquipmentMaintenanceController extends BaseController
{
    @Autowired
    private ITbEquipmentMaintenanceService tbEquipmentMaintenanceService;

    /**
     * 查询设备类型列表
     */
    @GetMapping("/list")
    public TableDataInfo list(TbEquipmentMaintenance tbEquipmentMaintenance)
    {
        startPage();
        List<TbEquipmentMaintenance> list = tbEquipmentMaintenanceService.selectTbEquipmentMaintenanceList(tbEquipmentMaintenance);
        return getDataTable(list);
    }

    /**
     * 导出设备类型列表
     */
    @Log(title = "设备类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbEquipmentMaintenance tbEquipmentMaintenance)
    {
        List<TbEquipmentMaintenance> list = tbEquipmentMaintenanceService.selectTbEquipmentMaintenanceList(tbEquipmentMaintenance);
        ExcelUtil<TbEquipmentMaintenance> util = new ExcelUtil<TbEquipmentMaintenance>(TbEquipmentMaintenance.class);
        util.exportExcel(response, list, "设备类型数据");
    }

    /**
     * 获取设备类型详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tbEquipmentMaintenanceService.selectTbEquipmentMaintenanceById(id));
    }

    /**
     * 新增设备类型
     */
    @Log(title = "设备类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbEquipmentMaintenance tbEquipmentMaintenance)
    {
        return toAjax(tbEquipmentMaintenanceService.insertTbEquipmentMaintenance(tbEquipmentMaintenance));
    }

    /**
     * 修改设备类型
     */
    @Log(title = "设备类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbEquipmentMaintenance tbEquipmentMaintenance)
    {
        return toAjax(tbEquipmentMaintenanceService.updateTbEquipmentMaintenance(tbEquipmentMaintenance));
    }

    /**
     * 删除设备类型
     */
    @Log(title = "设备类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tbEquipmentMaintenanceService.deleteTbEquipmentMaintenanceByIds(ids));
    }
}
